
using System;
using Unity.Entities;
using UnityEngine;

namespace Gj
{
    public class AnimationEffect : MonoBehaviour, ParticleEffect
    {
        public float time = 0;
        public float delayTime = 0;
        public ParticleSystem particle;
        public AudioClip clip;
        public SoundType soundType;

        public Entity GetEntity()
        {
            return Entity.Null;
        }

        public void Play()
        {
            if (delayTime > 0) Invoke(nameof(PlayAll), delayTime);
            else PlayAll();
        }

        void PlayAll()
        {
            if (soundType != SoundType.None)
                Game.single.PlayEFF(soundType);
            else if (clip != null) Game.single.PlayEFF(clip);
            
            if (particle != null) particle.Play();
            if (time > 0) Invoke(nameof(Stop), time);
        }

        public void Stop()
        {
            if (particle != null) particle.Stop();
        }
    }
}
    
